package com.aat.dizena.assist.web.controller;

import java.util.Date;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.aat.dizena.base.web.controller.BaseController;
import com.aat.dizena.utils.Atools;
import com.aat.dxfy.utils.EmailSendUtil;

/**
 * @time 2016-05-25
 * @author 新歌<xingeking@163.com>
 * @email xingeking@163.com
 * @version v1.0
 * @function 首页管理
 * @info java spring aop
 * @update none
 */

@Controller
@Scope("prototype")
@RequestMapping("assist")
public class EmailTelController extends BaseController {

	@Value("#{configProperties['email.username']}")
	private String emailUsername;

	@Value("#{configProperties['email.password']}")
	private String emailPassword;

	@Value("#{configProperties['email.link']}")
	private String emailLink;

	// 1-1,发送邮件验证码的接口；6位数字；
	@RequestMapping(value = "getEmailCode.do", method = RequestMethod.POST)
	@ResponseBody
	public String sendEmailCode(@RequestParam("e") String email) {
		try {
			if (Atools.checkEmail(email)) {
				String code = Atools.birthNumString(6);
				getSession().setAttribute(email, code);
				EmailSendUtil.sendMailSSL(email, "您的验证码是："+code, "巧了广告网站验证码");
				return "1";
			}
		} catch (Exception e) {
		}
		return "0";
	}

	// 2-1,发送邮件改密码连接页面的接口；
	@RequestMapping({ "getEmailLink.do" })
	@ResponseBody
	public void sendEmailLink(@RequestParam("e") String email) {
		try {
			long time = new Date().getTime() + 600000;
			String link = emailLink;
			link += "?sid=" + Atools.jiami(email);
			link += "&dt=" + Atools.jiami(Atools.getStrFmtTime("yyyy-MM-dd HH:mm:ss", new Date(time)));
			EmailSendUtil.sendMailSSL(email, "请点击如下链接：<a href='"+link+"'>"+link+"</a>", "巧了广告网站找回密码");
		} catch (Exception e) {

		}
	}

	// 3-1,发送短信验证码接口（图文验证码+手机号）
	@RequestMapping({ "getPhoneCode.do" })
	@ResponseBody
	public void sendPhoneCode(
			@RequestParam("c") String c,
			@RequestParam("p") String p) {
		try {
			String code = Atools.birthNumString(4);
			getSession().setAttribute(p, code);
			// 发送手机验证码

		} catch (Exception e) {

		}
	}

}
